package com.goodboys.base.config;

import com.goodboys.base.interceptor.BaseInterceptorConfig;
import com.goodboys.base.interceptor.JwtInterceptorConifg;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by baiguantao on 2017/6/28.
 * 参考:https://blog.csdn.net/u014042066/article/details/76702120
 */

@EnableWebMvc
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class CustomMVCConfiguration extends WebMvcConfigurerAdapter {

    /*
    //暂时关闭拦截器使用
    @Bean
    public JwtInterceptorConifg jwtInterceptorConifg(){
        return  new JwtInterceptorConifg();
    }*/

    //配置拦截器
   @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List list = new ArrayList<String>();
        list.add("/");
        list.add("/webjars/**");
        list.add("/message2");
        list.add("/");
        list.add("/lyou-websocket/**");
        list.add("/lyouws/*");
       list.add("/sys/addInfos");
       list.add("/sys/getDetail");
//        registry.addInterceptor(new BaseInterceptorConfig()).addPathPatterns("/**").excludePathPatterns(list);
//       list.add("/sys/**");
//        registry.addInterceptor(jwtInterceptorConifg()).addPathPatterns("/**").excludePathPatterns(list);
    }

    @Override
    public void addViewControllers( ViewControllerRegistry registry ) {
        //设置默认主页路径
        registry.addViewController( "/" ).setViewName( "/a" );
        registry.addViewController( "/message" ).setViewName( "/message" );
        registry.addViewController( "/message2" ).setViewName( "/message2" );
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE );
        super.addViewControllers( registry );
    }

    @Override
    public void configureContentNegotiation(
            ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
         //设置webjars资源路径
        if (!registry.hasMappingForPattern("/webjars/**")) {
            registry.addResourceHandler("/webjars/**").addResourceLocations(
                    "classpath:/META-INF/resources/webjars/");
        }
        super.addResourceHandlers(registry);
    }


}
